<?php
class TaxonomyHelper extends CHtml
{
    /**
     * activeDropDownList Taxonomy
     *
     * @param string $name
     * @param string $taxonomy
     * @param string $module
     * @param int $objectId
     * @param array $htmlOptions
     */
    public static function activeDropDownList($model, $attribute, $taxonomy, $module, $htmlOptions = array())
    {
        $properties = array(
            'model' => $model,
            'attribute' => $attribute,
            'taxonomy' => $taxonomy,
            'module' => $module,
            'objectId' => $model->getPrimaryKey(),
        );
        if (isset($htmlOptions['type'])) {
            $properties['type'] = CPropertyValue::ensureString($htmlOptions['type']);
            unset($htmlOptions['type']);
        }
        if (isset($htmlOptions['objectId'])) {
            $properties['objectId'] = CPropertyValue::ensureInteger($htmlOptions['objectId']);
            unset($htmlOptions['objectId']);
        }
        if (isset($htmlOptions['repeatChar'])) {
            $properties['repeatChar'] = CPropertyValue::ensureString($htmlOptions['repeatChar']);
            unset($htmlOptions['repeatChar']);
        }
        if (isset($htmlOptions['useRepeatChar'])) {
            $properties['useRepeatChar'] = CPropertyValue::ensureBoolean($htmlOptions['useRepeatChar']);
            unset($htmlOptions['useRepeatChar']);
        }
        $properties['htmlOptions'] = $htmlOptions;
        return Yii::app()->controller->widget('ListTaxonomy', $properties, true);
    }

    /**
     * activeRadioButtonList Taxonomy
     *
     * @param string $name
     * @param string $taxonomy
     * @param string $module
     * @param int $objectId
     * @param array $htmlOptions
     */
    public static function activeRadioButtonList($model, $attribute, $taxonomy, $module, $htmlOptions = array())
    {
        $htmlOptions = CMap::mergeArray(array('type' => 'radio'), $htmlOptions);
        return self::activeDropDownList($model, $attribute, $taxonomy, $module, $htmlOptions);
    }

    /**
     * checkBoxList Taxonomy
     *
     * @param string $name
     * @param string $taxonomy
     * @param string $module
     * @param int $objectId
     * @param array $htmlOptions
     */
    public static function activeCheckBoxList($model, $attribute, $taxonomy, $module, $htmlOptions = array())
    {
        $htmlOptions = CMap::mergeArray(array('type' => 'checkbox'), $htmlOptions);
        return self::activeDropDownList($model, $attribute, $taxonomy, $module, $htmlOptions);
    }

    /**
     * dropDownList Taxonomy
     *
     * @param string $name
     * @param string $taxonomy
     * @param string $module
     * @param int $objectId
     * @param array $htmlOptions
     */
    public static function dropDownList($name, $taxonomy, $module, $objectId, $htmlOptions = array())
    {
        $properties = array(
            'name' => $name,
            'taxonomy' => $taxonomy,
            'module' => $module,
            'objectId' => $objectId,
        );
        if (isset($htmlOptions['type'])) {
            $properties['type'] = CPropertyValue::ensureString($htmlOptions['type']);
            unset($htmlOptions['type']);
        }
        if (isset($htmlOptions['repeatChar'])) {
            $properties['repeatChar'] = CPropertyValue::ensureString($htmlOptions['repeatChar']);
            unset($htmlOptions['repeatChar']);
        }
        if (isset($htmlOptions['useRepeatChar'])) {
            $properties['useRepeatChar'] = CPropertyValue::ensureBoolean($htmlOptions['useRepeatChar']);
            unset($htmlOptions['useRepeatChar']);
        }
        $properties['htmlOptions'] = $htmlOptions;
        return Yii::app()->controller->widget('ListTaxonomy', $properties, true);
    }

    /**
     * radioButtonList Taxonomy
     *
     * @param string $name
     * @param string $taxonomy
     * @param string $module
     * @param int $objectId
     * @param array $htmlOptions
     */
    public static function radioButtonList($name, $taxonomy, $module, $objectId, $htmlOptions = array())
    {
        $htmlOptions = CMap::mergeArray(array('type' => 'radio'), $htmlOptions);
        return self::dropDownList($name, $taxonomy, $module, $objectId, $htmlOptions);
    }

    /**
     * checkBoxList Taxonomy
     *
     * @param string $name
     * @param string $taxonomy
     * @param string $module
     * @param int $objectId
     * @param array $htmlOptions
     */
    public static function checkBoxList($name, $taxonomy, $module, $objectId, $htmlOptions = array())
    {
        $htmlOptions = CMap::mergeArray(array('type' => 'checkbox'), $htmlOptions);
        return self::dropDownList($name, $taxonomy, $module, $objectId, $htmlOptions);
    }
}